package jpb;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * Defines constants for {@link JvmArg} implementations of the core (non-cutsom) arguments included in the
 * {@link Jvm} interface.
 *
 * @author Dariusz Kordonski
 */
public final class CoreJvmArgs {
    private CoreJvmArgs() {
        throw new AssertionError("Don't instantiate me");
    }

    public static enum Names {

        ENTRY_POINT("entry_point"),
        CLASS_PATH("class_path"),
        MAX_MEMORY("max_memory"),
        MIN_MEMORY("min_memory"),
        MAX_STACK_SIZE("max_stack_size"),
        SYSTEM_PROPERTIES("system_properties");

        private final String argName;

        private Names(String argName) {
            this.argName = argName;
        }

        public String argName() {
            return argName;
        }


        @Override
        public String toString() {
            return argName();
        }
    }

    @SuppressWarnings({"unchecked"})
    private static Class<List<File>> stupidHack() {
        return (Class) List.class;
    }

    @SuppressWarnings({"unchecked"})
    private static Class<Map<String,String>> anotherStupidHack() {
        return (Class) Map.class;
    }


    public static abstract class AbstractEntryPointArg extends JvmArg<EntryPoint> {

        protected AbstractEntryPointArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.ENTRY_POINT.argName(), EntryPoint.class);
        }
    }

    public static abstract class AbstractClassPathArg extends JvmArg<List<File>> {

        protected AbstractClassPathArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.CLASS_PATH.argName(), stupidHack());
        }
    }

    public static abstract class AbstractMaxMemoryArg extends JvmArg<MemArg> {

        protected AbstractMaxMemoryArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.MAX_MEMORY.argName(), MemArg.class);
        }
    }

    public static abstract class AbstractMinMemoryArg extends JvmArg<MemArg> {

        protected AbstractMinMemoryArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.MIN_MEMORY.argName(), MemArg.class);
        }
    }

    public static abstract class AbstractMaxStackSizeArg extends JvmArg<MemArg> {

        protected AbstractMaxStackSizeArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.MAX_STACK_SIZE.argName(), MemArg.class);
        }
    }

    public static abstract class AbstractSystemPropertiesArg extends JvmArg<Map<String,String>> {

        protected AbstractSystemPropertiesArg(Class<? extends Jvm> jvmClass) {
            super(jvmClass, Names.SYSTEM_PROPERTIES.argName(), anotherStupidHack());
        }
    }

}
